package org.itheima.mapper;


import org.apache.ibatis.annotations.*;
import org.itheima.pojo.User;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper {

    //用户名查询用户
    @Select("select * from user where username=#{username}")
    User findByUserName(String username);

    //注册
    @Insert("insert into user(username,password,create_time,update_time) values(#{username},#{password},now(),now())")
    void add(String username, String password);

    @Update("update user set nickname=#{nickname}, email=#{email},update_time=#{updateTime} where id=#{id}")
    void update(User user);

    @Update("update user set user_pic=#{avatarUrl},update_time=now() where id=#{id} ")
    void updateAvatar(String avatarUrl,Integer id);

    @Update("update user set password=#{md5String},update_time=now() where id=#{id}")
    void updatePwd(String md5String, Integer id);

    @Update("update user set personalIntroduction=#{newBio},email=#{newEmail} where id=#{id}")
    void updatePersonalIntroductionAndEmail(String newBio,String newEmail, Integer id);

    @Update("update user set nickname=#{nickname} where id=#{id}")
    void updateNickname(String nickname, Integer id);

    @Select("select * from user")
    List<Map<String,Object>> findAll();

    @Update("update user set status=2 where id=#{id}")
    void updateStatus(int id);

    @Update("update user set status=1 where id=#{id}")
    void updateStatus2(int id);

    @Select("select * from user where role=0")
    List<Map<String,Object>> findAllOrdinary();

}
